package org.gemstone.panel;

import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.come.entity.Goodstable;
import org.come.until.CutButtonImage;

import com.updateNew.MyIsif;
import org.come.until.MessagrFlagUntil;

public class GemstoneOperationRecastTypePanel extends JPanel {

    private JLabel[] labelRecast;
    private Goodstable[] Goodstablelabel;

    public GemstoneOperationRecastTypePanel() {

    		this.setBounds(42, 134, 228, 124);
            this.setOpaque(false);
            this.setLayout(null);

            class MListener extends MouseAdapter {

                private int num;

                public MListener(int num) {
                    // TODO Auto-generated constructor stub
                    this.num = num;
                }


                @Override
                public void mouseEntered(MouseEvent e) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                }
                @Override
                public void mouseClicked(MouseEvent e) {
                    // TODO Auto-generated method stub
                    GemstoneOperationMainCardPanel gemstoneOperationMainCardPanel = GemstoneOperationMainFrame
                            .getGemstoneOperationMainFrame().getGemstoneOperationMainPanel()
                            .getGemstoneOperationMainCardPanel();
                    gemstoneOperationMainCardPanel.getGemstoneOperationAppraisalAndRecastPanel().getReelectGoods()
                            .setType(Goodstablelabel[num].getType());
                    gemstoneOperationMainCardPanel.getGemstoneOperationAppraisalAndRecastPanel().getRecastGemstone()
                            .setIcon(CutButtonImage.getGemstoneIcon((Goodstablelabel[num].getSkin()) + "", 48, 48));

                    gemstoneOperationMainCardPanel.getGemstoneOperationAppraisalAndRecastPanel()
                            .getGemstoneOperationRecastTypePanel().setVisible(false);
                }
            }

            labelRecast = new JLabel[8];
            Goodstablelabel = new Goodstable[8];
            for (int i = 0; i < labelRecast.length; i++) {
                labelRecast[i] = new JLabel();
                labelRecast[i].setBounds(11 + i % 4 * 51, 11 + i / 4 * 51, 48, 48);
                labelRecast[i].addMouseListener(new MListener(i));
                labelRecast[i].setOpaque(false);
                this.add(labelRecast[i]);
            }
            for (int i = 0; i < Goodstablelabel.length; i++) {
                Goodstablelabel[i] = new Goodstable();
                Goodstablelabel[i].setType(746L + i * 3);
            }

    }

    private ImageIcon iconBack;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        	if (iconBack == null) {
                iconBack = new ImageIcon("inkImg/old/background/S44.png");
            }
            g.drawImage(iconBack.getImage(), 0, 0, 228, 124, this);


    }

    // 刷新宝石类型图片
    public void repaintGemstoneIcon() {
        int num = 0;
        int parseInt = Integer.parseInt(GemstoneOperationMainFrame
                .getGemstoneOperationMainFrame()
                .getGemstoneOperationMainPanel()
                .cuttingString(
                        GemstoneOperationMainFrame.getGemstoneOperationMainFrame().getGemstoneOperationMainPanel()
                                .getGoodsLabes()[0], 1));
        if (parseInt <= 3) {
            num = 0;
        } else if (parseInt <= 6) {
            num = 1;
        } else {
            num = 2;
        }
        GemstoneOperationMainFrame
                .getGemstoneOperationMainFrame()
                .getGemstoneOperationMainPanel()
                .getGemstoneOperationMainCardPanel()
                .getGemstoneOperationAppraisalAndRecastPanel()
                .getRecastGemstone()
                .setIcon(
                        CutButtonImage.getGemstoneIcon((GemstoneOperationMainFrame.getGemstoneOperationMainFrame()
                                .getGemstoneOperationMainPanel().getGoodsLabes()[0].getSkin())
                                + "", 48, 48));

        for (int i = 0; i < labelRecast.length; i++) {
            labelRecast[i].setIcon(CutButtonImage.getGemstoneIcon((746 + num + i * 3) + "", 48, 48));
            Goodstablelabel[i].setSkin((746 + num + i * 3) + "");
            Goodstablelabel[i].setType(746L + i * 3);
        }
    }

    public JLabel[] getLabelRecast() {
        return labelRecast;
    }

    public void setLabelRecast(JLabel[] labelRecast) {
        this.labelRecast = labelRecast;
    }

    public ImageIcon getIconBack() {
        return iconBack;
    }

    public void setIconBack(ImageIcon iconBack) {
        this.iconBack = iconBack;
    }

}
